<?xml version="1.0"?>
<OnTheFlyInstruction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <InstanceId>SPCTypeInfoSample</InstanceId>
  <CustomAppConfig />
  <Tags>
    <string>SharePoint</string>
  </Tags>
  <AdditionalAssemblies />
  <Code><![CDATA[// Check content type usage
// v 1.0 - 2013_07_16 - rev 0

using System;using xSolon.Instructions.DTO;
using System.Linq;using System.Data;
using xSolon.Instructions;using System.Collections.Generic;
using Microsoft.SharePoint;using System.Xml;
using xSolon.Instructions.SP;using System.Text;

public class SPCTypeInfoSample : AbstractInstruction
{

	public override void Run()
	{

		using (var site = new SPSite("http://localhost"))
		using (var web = site.OpenWeb())
		{
			
			var cType = web.AvailableContentTypes["Audio"];
			
			var usages = SPContentTypeUsage.GetUsages(cType);
			
			NotifyInformation("Usages: {0}", usages.Count);
			
			foreach (SPContentTypeUsage usage in usages)
               {
               	  NotifyInformation(usage.Url);
               }
			
			
			site.AllWebs.ToList().ForEach(i =>{
				foreach(SPList list in i.Lists){
					NotifyInformation(list.DefaultViewUrl);
					foreach(SPContentType iCType in list.ContentTypes)
					{
						if (cType.Id.IsParentOf(iCType.Id))
						{
							NotifyInformation(list.DefaultViewUrl);
						}
					}
					
					/*try{
					
					var childId = list.GetDirectChildContentType(cType.Id);
					
					NotifyInformation(childId.ToString());
					}
					catch{}
					*/
				}
			});
		}

	}

	// formats xml document
	static public string Beautify(XmlDocument doc)
	{//http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
	    StringBuilder sb = new StringBuilder();
	    XmlWriterSettings settings = new XmlWriterSettings();
	    settings.Indent = true;
	    settings.IndentChars = "  ";
	    settings.NewLineChars = "\r\n";
	    settings.NewLineHandling = NewLineHandling.Replace;
	    using (XmlWriter writer = XmlWriter.Create(sb, settings)) {
	        doc.Save(writer);
	    }
	    return sb.ToString();
	}
	
}]]></Code>
</OnTheFlyInstruction>